﻿/**
 * Copyright (C) 2011 original author and authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace NGuice.Inject.Internal.Util
{
    internal sealed class ReadOnlyDictionary: IDictionary
    {
        private IDictionary source;

        public ReadOnlyDictionary(IDictionary source)
        {
            if (source == null)
                source = new EmptyDictionary();
            this.source = source;
        }

        public void Add(object key, object value)
        {
            throw new NotImplementedException();
        }

        public void Clear()
        {
            throw new NotImplementedException();
        }

        public bool Contains(object key)
        {
            return this.source.Contains(key);
        }

        public IDictionaryEnumerator GetEnumerator()
        {
            return this.source.GetEnumerator();
        }

        public bool IsFixedSize
        {
            get { return true; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public ICollection Keys
        {
            get { return this.source.Keys; }
        }

        public void Remove(object key)
        {
            throw new NotImplementedException();
        }

        public ICollection Values
        {
            get { return this.source.Values; }
        }

        public object this[object key]
        {
            get
            {
               return this.source[key];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public void CopyTo(Array array, int index)
        {
            this.source.CopyTo(array, index);
        }

        public int Count
        {
            get { return this.source.Count; }
        }

        public bool IsSynchronized
        {
            get { return this.source.IsSynchronized; }
        }

        public object SyncRoot
        {
            get { return this.source.SyncRoot; }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.source.GetEnumerator();
        }
    }

    internal class EmptyDictionary : IDictionary
    {
        public void Add(object key, object value)
        {
            
        }

        public void Clear()
        {
           
        }

        public bool Contains(object key)
        {
            return false;
        }

        public IDictionaryEnumerator GetEnumerator()
        {
            return null;
        }

        public bool IsFixedSize
        {
            get { return true; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public ICollection Keys
        {
            get { return new object[0].ToList(); }
        }

        public void Remove(object key)
        {
            
        }

        public ICollection Values
        {
            get { return new object[0].ToList(); }
        }

        public object this[object key]
        {
            get
            {
                return null;
            }
            set
            {
                
            }
        }

        public void CopyTo(Array array, int index)
        {
            
        }

        public int Count
        {
            get { return 0; }
        }

        public bool IsSynchronized
        {
            get { return false ; }
        }

        public object SyncRoot
        {
            get { return null; ; }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return new object[0].ToList().GetEnumerator();
        }
    }
}
